<template>
    <div class="overview-card">
        <div class="head">
            <h3>{{cardName}}</h3>
            <btn-group :showBtn="showBtn" :listUrl="listUrl"/>
        </div>
        <div class="card">
            <ul>
                <li v-for="item in cardData" :class="{pointer: item.url}" @click="toPage(item.url)">
                    <p class="rote"><span>{{item.number || 0}}</span>{{item.unit}}</p>
                    <p class="text">
                        {{item.name}}
                        <el-tooltip class="item" effect="light" placement="right" v-if="!showTooltip">
                            <div slot="content">
                                同比
                                <span :class="{'tooltips-red': item.intuitive > 0, 'tooltips-blue': item.intuitive < 0}">
                                    <i v-if="item.intuitive > 0" class="el-icon-top top"></i><i v-if="item.intuitive < 0" class="el-icon-bottom bottom"></i>{{Math.abs(item.intuitive)}}{{item.tipsUnit}}
                                </span>
                            </div>
                            <span :class="{'red': item.intuitive > 0, 'blue': item.intuitive < 0}">
                                <i v-if="item.intuitive > 0" class="el-icon-top top"></i><i v-if="item.intuitive < 0" class="el-icon-bottom bottom"></i>{{Math.abs(item.intuitive)}}{{item.tipsUnit}}
                            </span>
                        </el-tooltip>
                    </p>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
    import BtnGroup from '@/components/BtnGroup'
    import {Bus} from '@/utils/bus'

    export default {
        name: 'index',
        props: ['cardName', 'cardData', 'listUrl'],
        data () {
            return {
                // 百分比
                percentage: 99.9,
                // 显示按钮
                showBtn: ['summyList'],
                // 是否显示同比值（取反）
                showTooltip: false
            }
        },
        mounted () {
            this.showTooltip = this.getLocalStorage('globalSearchUnit', 'timeUnit') === 'year'
            Bus.$on('globalSearch', () => {
                this.showTooltip = this.getLocalStorage('globalSearchUnit', 'timeUnit') === 'year'
            })
        },
        methods: {
            /**
             * 跳转页面
             * @param url 跳转地址
             */
            toPage (url) {
                if (url) this.$router.push(url)
            }
        },
        components: {
            BtnGroup
        },
        beforeDestroy () {
            Bus.$off('globalSearch')
        }
    }
</script>

<style scoped lang="scss">
    .overview-card {
        background: #fff;
        padding: 0 10px;
        .head {
            display: flex;
            justify-content: space-between;
            align-items: center;
            h3 {
                font-size: 16px;
                color: #000;
                font-weight: 600;
                line-height: 48px;
            }
        }
        .card {
            padding-bottom: 10px;
            ul {
                padding: 0;
                margin: 0;
                border: 1px solid transparent;
                display: flex;
                justify-content: flex-start;
                align-items: center;
                flex-wrap: wrap;
                li {
                    padding: 10px;
                    margin: 10px 10px 0 0;
                    width: calc(25% - 10px);
                    border: 1px solid #ebeef5;
                    border-radius: 4px;
                    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
                    &.pointer {
                        cursor: pointer;
                    }
                    &:nth-child(4n) {
                        margin-right: 0;
                    }
                    p {
                        margin: 0;
                    }
                    .rote {
                        font-size: 14px;
                        color: #333;
                        span {
                            font-size: 24px;
                            font-weight: 600;
                        }
                    }
                    .text {
                        font-size: 14px;
                        .top {

                        }
                        .bottom {

                        }
                        span {
                            font-size: 16px;
                            color: #333;
                            &.blue {
                                color: #139ce4;
                            }
                            &.red {
                                color: #e21f06;
                            }
                        }
                    }
                }
            }
        }
    }
</style>
<style lang="scss">
    .tooltips-blue {
        color: #139ce4;
    }
    .tooltips-red {
        color: #e21f06;
    }
</style>
